Indicators at a Glance

Macroeconomic Conditions

Gross Domestic Product (as of Jan 1 2023)

$26.466 Trillion

Unemployment Rate (as of Apr 1 2023)

3.4%

Consumer Price Index — Percent Change from 1 Year Ago (as of Apr 1 2023)

4.96%

Asset Prices

Federal Funds Rate (as of Apr 1 2023)

4.83%

Gas Price (as of May 8 2023)

$3.53/gallon

Oil Price (as of May 8 2023)

$73.13/barrel

Average 30-Year Fixed Mortgage Rate (as of May 11 2023)

6.35%

Key Prices

Column

Federal Funds Rate

Column

Chart B

Chart C

Gasoline

Column

Gasoline

Column

Oil

---
title: "Key U.S. Economic Indicators"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

 




```{r setup, include=FALSE}
library(here)
library(tidyverse)
here::i_am("econ_dash.Rmd")

path <- here::here("scripts")            # scripts source
source_files <- list.files(path, "*.R$")  # locate all .R files
map(paste0(path, "/", source_files), source)  # source all .R scripts
```

```{r}
# Fed Funds Rate
ffr_latest <- paste0(get_latest_value(ffr),"%")
ffr_latest_date <- get_latest_date(ffr)

# Gas Price
gas_latest <- paste0("$", round(get_latest_value(gas), 2), "/gallon")
gas_latest_date <- get_latest_date(gas)

# Oil Price
oil_latest <- paste0("$", round(get_latest_value(oil), 2), "/barrel")
oil_latest_date <- get_latest_date(oil)

# Fed Funds Rate
cpi_latest <- paste0(round(get_latest_value(cpi),2),"%")
cpi_latest_date <- get_latest_date(cpi)

# Mortgage Rate
mortgage_latest <- paste0(round(get_latest_value(mortgage),2),"%")
mortgage_latest_date <- get_latest_date(mortgage)

# GDP 
gdp_latest <- paste0("$",round(0.001*get_latest_value(gdp),3), " Trillion")
gdp_latest_date <- get_latest_date(gdp)

# Real GDP
rgdp_latest <- paste0("$",round(get_latest_value(rgdp),0))
rgdp_latest_date <- get_latest_date(rgdp)

# Real GDP per Capita
rgdp_pc_latest <- paste0("$",round(get_latest_value(rgdp_pc),0))
rgdp_pc_latest_date <- get_latest_date(rgdp_pc)

# Real GDP Growth Rate
rgdp_growth_latest <- paste0(round(get_latest_value(rgdp_growth),2),"%")
rgdp_growth_latest_date <- get_latest_date(rgdp_growth)

# Unemployment Rate
ur_latest <- paste0(round(get_latest_value(ur),2),"%")
ur_latest_date <- get_latest_date(ur)
```

```{r, eval=F}
ffr_current <- ffr %>%
  arrange(desc(date)) %>%
  slice(1) %>%
  pull(value) %>%
  paste0(., "%")

ffr_current_date <- ffr %>%
  arrange(desc(date)) %>%
  slice(1) %>%
  pull(date)
```

Indicators at a Glance
===============

Macroeconomic Conditions {data-width=650}
-------------------------

### Gross Domestic Product (as of `r gdp_latest_date`) {.value-box}

```{r}
valueBox(value = gdp_latest, icon = "fa-tag")
```

### Unemployment Rate (as of `r ur_latest_date`) {.value-box}

```{r}
valueBox(value = ur_latest, icon = "fa-percent")
```

### Consumer Price Index — Percent Change from 1 Year Ago (as of `r cpi_latest_date`) {.value-box}

```{r}
valueBox(value = cpi_latest, icon = "fa-solid fa-money-bill-trend-up")
```


Asset Prices {data-width=650}
--------------------------

### Federal Funds Rate (as of `r ffr_latest_date`) {.value-box}

```{r}
valueBox(value = ffr_latest, icon = "fa-percent")
```

### Gas Price (as of `r gas_latest_date`) {.value-box}

```{r}
valueBox(value = gas_latest, icon = "fa-gas-pump")
```

### Oil Price (as of `r oil_latest_date`) {.value-box}

```{r}
valueBox(value = oil_latest, icon = "fa-oil-well")
```


### Average 30-Year Fixed Mortgage Rate (as of `r mortgage_latest_date`) {.value-box}

```{r}
valueBox(value = mortgage_latest, icon = "fa-solid fa-house")
```


Key Prices
=======================================================================

Column {data-width=650}
-----------------------------------------------------------------------

### Federal Funds Rate

```{r}
plot_ffr <-ggplot(data = ffr)+
    aes(x = date,
        y = value,
        color = series_id)+
    geom_rect(data = recs, 
              aes(xmin = start, xmax = end, ymin = -Inf, ymax = Inf),
              inherit.aes = FALSE, fill = "black", alpha = 0.3)+
    geom_path(size=1)+
    geom_hline(yintercept=0, size=1)+
    scale_x_date(limits=as.Date(c("1955-01-01", "2022-07-01")),
                 date_breaks = "5 years",
                 #minor_breaks = "2 years",
                 date_labels = "%Y",
                 expand = c(0,0))+
    scale_y_continuous(breaks=seq(0,20,2),
                       labels=function(x){paste0(x,"%")},
                       limits = c(0,20),
                       expand = c(0,0))+
    labs(x = "Year",
         y = "Federal Funds Rate",
         caption = "Data Source: FRED; Recessions Shaded in Gray")+
    theme_classic(base_family = "Fira Sans Condensed", base_size = 16)+
    theme(legend.position="none")

plot_ffr # %>% plotly::ggplotly()
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B

```{r}
library(xts)
ffr %>% 
  select(value) %>%
  rename("Fed Funds Rate" = value) %>% 
  xts(., order.by = as.Date(ffr$date)) %>% 
  dygraph() %>%
  dyRangeSelector()
```

### Chart C

```{r}
library(highcharter)
hchart(ffr, "line", hcaes(x = date, y = value))
  
```

Gasoline
===============

Column {data-width=650}
-----------------------------------------------------------------------

### Gasoline

```{r}
plot_gas <-ggplot(data = gas)+
    aes(x = date,
        y = value,
        color = series_id)+
    geom_rect(data = recs, 
              aes(xmin = start, xmax = end, ymin = -Inf, ymax = Inf),
              inherit.aes = FALSE, fill = "black", alpha = 0.3)+
    geom_path(size=1)+
    geom_hline(yintercept=0, size=1)+
    scale_x_date(limits=as.Date(c("1990-01-01", gas_latest_date)),
                 date_breaks = "2 years",
                 minor_breaks = "2 years",
                 date_labels = "%Y",
                 expand = c(0,0))+
    scale_y_continuous(breaks=seq(0,5.25,0.25),
                       labels=scales::dollar_format(),
                       limits = c(0,5.25),
                       expand = c(0,0))+
    labs(x = "Year",
         y = "Price/gal",
         subtitle = "US Regular All Formulations Gas Price",
         caption = "Data Source: FRED; Recessions Shaded in Gray")+
    ggthemes::theme_pander(base_family = "Fira Sans Condensed", base_size = 16)+
    theme(legend.position="none")

plot_gas #%>% plotly::ggplotly()
```

Column {data-width=650}
-----------------

### Oil

```{r}
plot_oil <- ggplot(data = oil)+
    aes(x = date,
        y = value,
        color = series_id)+
    geom_rect(data = recs, 
              aes(xmin = start, xmax = end, ymin = -Inf, ymax = Inf),
              inherit.aes = FALSE, fill = "black", alpha = 0.3)+
    geom_path(size=1)+
    geom_hline(yintercept=0, size=1)+
    scale_x_date(limits=as.Date(c("1950-01-01", oil_latest_date)),
                 date_breaks = "5 years",
                 minor_breaks = "2 years",
                 date_labels = "%Y",
                 expand = c(0,0))+
    scale_y_continuous(breaks=seq(0,150,20),
                       labels=scales::dollar_format(),
                       limits = c(0,150),
                       expand = c(0,0))+
    labs(x = "Year",
         y = "Price/barrel",
         subtitle = "Crude Oil Prices: West Texas Intermediate (WTI) - Cushing, Oklahoma",
         caption = "Data Source: FRED; Recessions Shaded in Gray")+
    ggthemes::theme_pander(base_family = "Fira Sans Condensed", base_size = 16)+
    theme(legend.position="none")

plot_oil #%>% plotly::ggplotly()

```